package com.m31skytech.dungeonstool;

import com.mojang.logging.LogUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.ItemBlockRenderTypes;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.material.Material;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.config.ModConfig;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.event.server.ServerStartingEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;

// The value here should match an entry in the META-INF/mods.toml file
@Mod(DungeonsTool.MODID)
public class DungeonsTool
{
    // 定义所有地方通用的模组ID
    public static final String MODID = "dungeonstool";
    // 直接引用 slf4j 日志记录器
    private static final Logger LOGGER = LogUtils.getLogger();

    public DungeonsTool()
    {
        IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
        // 将延迟注册器注册到模组事件总线，以便注册方块
        BlockRegistry.BLOCKS.register(modEventBus);
        // 将延迟注册器注册到模组事件总线，以便注册方块实体
        BlockEntityRegistry.BLOCK_ENTITIES.register(modEventBus);
        // 将延迟注册器注册到模组事件总线，以便注册物品
        ItemRegistry.ITEMS.register(modEventBus);
        // 将自身注册到我们感兴趣的服务器和其他游戏事件
        MinecraftForge.EVENT_BUS.register(this);
        // 注册模组的 ForgeConfigSpec，以便 Forge 可以为我们创建和加载配置文件
        ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, Config.SPEC);
        // 注册用于模组加载的 commonSetup 方法
        modEventBus.addListener(this::commonSetup);
    }

    private void commonSetup(final FMLClientSetupEvent event)
    {
        //创造模式标签
        DTCreateTab.register();

//        Config.items.forEach((item) -> LOGGER.info("ITEM >> {}", item.toString()));
    }

    // 你可以使用 SubscribeEvent 并让事件总线发现要调用的方法
    @SubscribeEvent
    public void onServerStarting(ServerStartingEvent event)
    {
        // 在服务器启动时执行某些操作
        LOGGER.info("HELLO from server starting");
    }

    // 你可以使用 EventBusSubscriber 自动注册使用 @SubscribeEvent 注释的类中的所有静态方法
    @Mod.EventBusSubscriber(modid = DungeonsTool.MODID, bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
    public static class ClientModEvents
    {
        @SubscribeEvent
        public static void onClientSetup(FMLClientSetupEvent event)
        {
            // Some client setup code
            LOGGER.info("HELLO FROM CLIENT SETUP");
            LOGGER.info("MINECRAFT NAME >> {}", Minecraft.getInstance().getUser().getName());
        }
    }

}
